package com.tuosha.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tuosha.dao.MoneyRecordsDao;
import com.tuosha.model.MoneyRecordsEntity;
import com.tuosha.service.MoneyRecordsService;



@Service("moneyRecordsServiceImpl")
public class MoneyRecordsServiceImpl implements MoneyRecordsService {
	@Autowired
	private MoneyRecordsDao moneyRecordsDao;
	
	@Override
	public MoneyRecordsEntity queryObject(Integer id){
		return moneyRecordsDao.queryObject(id);
	}
	
	@Override
	public List<MoneyRecordsEntity> queryList(Map<String, Object> map){
		return moneyRecordsDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return moneyRecordsDao.queryTotal(map);
	}
	
	@Override
	public void save(MoneyRecordsEntity moneyRecords){
		Date date=new Date();
		moneyRecords.setCreatedAt(date);
		moneyRecordsDao.save(moneyRecords);
	}
	
	@Override
	public int update(MoneyRecordsEntity moneyRecords){
		Date date=new Date();
		moneyRecords.setUpdatedAt(date);
		return moneyRecordsDao.update(moneyRecords);
	}
	
	@Override
	public int delete(Integer id){
		return moneyRecordsDao.delete(id);
	}
	
	@Override
	public int deleteBatch(Integer[] ids){
		return moneyRecordsDao.deleteBatch(ids);
	}

	public int delById(Integer id){

		MoneyRecordsEntity record= new MoneyRecordsEntity();
		Date date=new Date();
		record.setId(id);
		record.setDeletedAt(date);
		record.setStatus("0");
		record.setType("0");
		return moneyRecordsDao.update(record);
	}

	public int delPatch(String  tiestr){
		String[] strs = tiestr.split(",");
		if(strs!=null&&strs.length>0){
			for (String str : strs) {
				delById(Integer.parseInt(str));
			}
		}
		return 0;
	}
	
}
